using System;
using System.Collections.Generic;
using Sce.PlayStation.Core.Graphics;
namespace Nyanimals
{
	public sealed class CTextureManager
	{
		private static readonly CTextureManager instance = new CTextureManager();
		private List<tTexture> Textures;
		
		private CTextureManager ()
		{
			Textures = new List<tTexture>();
		}
		
		public static CTextureManager Instance
		{
			get { return instance;}
		}
		
		public void GetTexture(int index, out tTexture tex)
		{
			tex = Textures[index];
		}
		
		public int LoadTexture(string szName)
		{
			// check if the texture is in existance
			for(int textureIndex = 0; textureIndex < Textures.Count; ++textureIndex)
			{
				if(Textures[textureIndex].Name == szName)
				{
					return textureIndex;
				}
			}
			
			// create and add a new texture
			tTexture tex = new tTexture();
			tex.Name = new string(szName.ToCharArray());
			
			string szFullPath = "/Application/Resources/Textures/" + szName;
			//szFullPath = szFullPath.Remove(szFullPath.LastIndexOf("."));
			//szFullPath += ".jpg";
			tex.Texture = new Texture2D(szFullPath, false);
			tex.Texture.SetWrap(TextureWrapMode.Repeat);
            
			int returnIndex = Textures.Count;
			Textures.Add(tex);
			
			return returnIndex;
		}
	}
}

